<style scoped lang="less">
.threshold-ipt{
    padding: 0 10px;
    height: 32px;
    line-height: 32px;
    width: 100px;
    // background: #1E3C88;
    border:1px solid transparent;
    &:focus{
        border-color: rgba(255,255,255,.4);
    }
}
/deep/.el-table__header-wrapper {
    height: 0px !important;
}
/deep/.el-switch__label {
    color: #fff !important;
}
/deep/ .el-table .el-table__body-wrapper td {
    border-top: none !important;
}
</style>
<template>
	<div class="threshold">
		<el-table 
			:data="dataList" 
			style="width: 100%"
			v-loading="loading">
		    <!-- <el-table-column prop="name" label="名称"></el-table-column> -->
		    <!-- <el-table-column prop="voiceInterval" label="间隔"></el-table-column> -->
		    <el-table-column prop="msgState"  v-if="hasPermission('017005001')">
                <template slot-scope="scope">
                    <el-switch
                        v-model="scope.row.msgOpen"
                        active-color="#13ce66"
                        inactive-text="发送短信"
                        @change="msgChange($event,scope.row)">
                    </el-switch>
                    <!-- {{scope.row.msgState == 1? '发送' : '不发送'}} -->
                </template>
            </el-table-column>
		    <el-table-column prop="voiceState"  v-if="hasPermission('017005002')">
                <template slot-scope="scope">
                    <el-switch
                        v-model="scope.row.voiceOpen"
                        active-color="#13ce66"
                        inactive-text="发送语音"
                        @change="voiceChange($event,scope.row)">
                    </el-switch>
                    <!-- {{scope.row.voiceState == 1? '发送' : '不发送'}} -->
                </template>
            </el-table-column>
		    <!-- <el-table-column label="操作" width="240">
		    	<template slot-scope="scope">
                    <el-button type="danger" v-if="scope.row.msgState==1">关闭短信发送</el-button>
                    <el-button type="green" v-if="scope.row.msgState==2">开启短信发送</el-button>
                    <el-button type="danger" v-if="scope.row.voiceState==1">关闭语音发送</el-button>
                    <el-button type="green" v-if="scope.row.voiceState==2">开启语音发送</el-button>
                </template>
		    </el-table-column> -->
		</el-table>
	</div>
</template>
<script>
export default {
	name: 'iotBlk',
	props: {
		number: {
			type: String,
			default: ''
        },
        deviceClassify: {
			type: String,
			default: ''
        },
	},
	computed: {},
	watch: {},
	data () {
		return {
            loading: false,
            dataList: []
		}
	},
	methods: {
		getData () {
            this.$get('/fireFightingIOT/itemSetup/getSendMsgStateList', {number: this.number,deviceClassify: this.deviceClassify}).then(res => {
            	this.loading = false
                this.dataList = res.data.map(item=>{
                    item.msgOpen = item.msgState == 1
                    item.voiceOpen = item.voiceState == 1
                    return item
                })
            }, (err) =>{
            	this.loading = false
				if(err.msg){
					this.$message.error(err.msg);
				}
            })
        },
        msgChange (value,item) {
            this.$post('/fireFightingIOT/itemSetup/insertSendMsgState',{
                number:this.number,
                deviceClassify: item.deviceClassify,
                msgState: value ? 1 : 2,
                voiceState: item.voiceState
            }).then(res=>{
                this.$message.success('操作成功')
                this.getData ();
            },err=>{
                this.$message.error(err.msg)
            })
        },
        voiceChange (value,item) {
            this.$post('/fireFightingIOT/itemSetup/insertSendMsgState',{
                number:this.number,
                deviceClassify: item.deviceClassify,
                voiceState: value ? 1 : 2,
                msgState: item.msgState
            }).then(res=>{
                this.$message.success('操作成功')
                this.getData ();
            },err=>{
                this.$message.error(err.msg)
            })
        },
	},
	created () {
		this.getData()
	},
}
</script>